package com.yx.backstage.converter;

import cn.hutool.core.date.DateUtil;
import com.yx.backstage.model.DictMessage;
import com.yx.backstage.model.vo.DictMessageVo;
import com.yx.backstage.util.TimeFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author YangXiong
 */
public class DictMessageConverter {

    public static List<DictMessageVo> handlerDictResult(List<DictMessage> list) {
        List<DictMessageVo> result = new ArrayList<>();
        list.forEach(dict->{
            DictMessageVo vo = getDictMessageVo(dict);
            result.add(vo);
        });
        return result;
    }

    public static DictMessageVo getDictMessageVo(DictMessage dict) {
        DictMessageVo vo = new DictMessageVo();
        vo.setId(dict.getId());
        vo.setName(dict.getName());
        vo.setRemark(dict.getRemark());
        vo.setEnable(dict.getEnable());
        Date modifyTime = dict.getModifyTime();
        String format = DateUtil.format(modifyTime, TimeFormat.TIME_FORMAT);
        vo.setModifyTime(format);
        vo.setOperatorName(dict.getOperatorName());
        vo.setText(dict.getText());
        vo.setIsChild(dict.getIsChild());
        vo.setParentId(dict.getParentId());
        vo.setType(dict.getType());
        vo.setValue(dict.getValue());
        return vo;
    }
}
